package com.itheima.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class RabbitmqSend {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 发送延时消息
     * delayTime 延迟的时间 单位是毫秒
     *
     * @param msg
     */
    public void sendDelayMessage(Object msg, String routingKey, Long delayTime) {
        rabbitTemplate.convertAndSend("delay_exchange", routingKey, msg,
                message -> {
                    //设置延迟时间  
                    message.getMessageProperties().setHeader("x-delay", delayTime);
                    return message;
                });
    }
}